package com.pinla.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.pinla.common.servlet.Configuration;



public class CreateOrderIDUtil {
	public static int no = 1;//展销平台订单ID
	
	public static int user_no = 1;//展销平台用户ID

	public static final Object LOCK = new Object();

	/**
	 * 生成192.0展销平台的订单号
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateAGOrderID() {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		
		StringBuffer sb = new StringBuffer("AG");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	public static String CreateOrderBakID() {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		
		StringBuffer sb = new StringBuffer("BG");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/**
	 * 生成192.0发票打印设置表id
	 * 
	 * @author liufeng
	 * @param
	 * @return String -发票号
	 * @throws
	 */
	public static String CreateSetupId() {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		
		StringBuffer sb = new StringBuffer("FP");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	/**
	 * 生成alipay的订单号
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String getAlipayOrderID() {

		String FORMAT1 = "MMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		
		StringBuffer sb = new StringBuffer("");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/**
	 * 生成192.0展销平台的退款申请流水号
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateRefundID() {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		StringBuffer sb = new StringBuffer("RQ");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/**
	 * 生成192.0展销平台的退款任务流水号
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateRefundTaskID() {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		StringBuffer sb = new StringBuffer("RF");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	
	/**
	 * 生成192.0话费批量重置批次号
	 * 
	 * @author chendi
	 * @param
	 * @return String - 批次号
	 * @throws
	 */
	public static String CreateHfBatchID() {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		StringBuffer sb = new StringBuffer("HB");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}

	/**
	 * 生成19e2.0展销平台的代理商ID
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateAGUserID() {

		String FORMAT1 = "yyyyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (user_no > 9999) {
				user_no = 1000;
			}
			current += user_no++;
		}

		StringBuffer sb = new StringBuffer("DL");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}

	/**
	 * 生成19e2.0展销平台的代理商ID
	 * 
	 * @author zhongsb
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateAGStaffID() {

		String FORMAT1 = "yyyyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (user_no > 9999) {
				user_no = 1000;
			}
			current += user_no++;
		}

		StringBuffer sb = new StringBuffer("WK");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/**
	 * 生成19e2.0展销平台的代理商的收款地址ID
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateReceiverAddressID() {

		String FORMAT1 = "yyyyMMddHH";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (user_no > 9999) {
				user_no = 1000;
			}
			current += user_no++;
		}

		StringBuffer sb = new StringBuffer("");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/**
	 * 生成19e2.0展销平台的线下汇款的申请单号
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateRemitID() {

		String FORMAT1 = "yyyyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (user_no > 9999) {
				user_no = 1000;
			}
			current += user_no++;
		}

		StringBuffer sb = new StringBuffer("");
		//sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}	
	
	/**
	 * 生成19e2.0展销平台的线下汇款的申请单号
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateReimburseID() {

		String FORMAT1 = "yyyyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (reim_no > 9999) {
				reim_no = 1000;
			}
			current += reim_no++;
		}

		StringBuffer sb = new StringBuffer("");
		sb.append(tranDate).append(current);
		return sb.toString();
	}
	
	/**
	 * 按分库ID,平台ID,时间生成19e2.0展销平台的订单号
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String createAGOrderID(String dbx){

		String FORMAT1 = "yyMMddHHmm";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}
		
		StringBuffer sb = new StringBuffer("AG");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(dbx);
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/**
	 * 生成192.0展销平台的退款任务流水号
	 * 
	 * @author zhyue3h
	 * @param
	 * @return String - 订单号
	 * @throws
	 */
	public static String CreateRefundTaskID(String dbx) {

		String FORMAT1 = "yyMMddHHmm";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		StringBuffer sb = new StringBuffer("RF");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(dbx);
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/**
	 * 生成192.0话费批量重置批次号
	 * 
	 * @author chendi
	 * @param
	 * @return String - 批次号
	 * @throws
	 */
	public static String CreateHfBatchID(String dbx) {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		StringBuffer sb = new StringBuffer("HB");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(dbx);
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	public static int reim_no = 1;//展销平台返点ID
	
	public static String CreateCommonID() {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		StringBuffer sb = new StringBuffer("00");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/**
	 * 生成193.0提交意见ID号
	 * 
	 * @author chendi
	 * @param
	 * @return String - 提交意见ID号
	 * @throws
	 */
	public static String CreateAdviceID(String dbx) {

		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 1000;
		synchronized (LOCK) {
			if (no > 9999) {
				no = 1000;
			}
			current += no++;
		}

		StringBuffer sb = new StringBuffer("AD");
		sb.append(null==Configuration.getValue("WEB_GW_NO")?"99":Configuration.getValue("WEB_GW_NO"));
		sb.append(dbx);
		sb.append(tranDate).append(current);

		return sb.toString();
	}
	
	/** 
	* @方法名: CreateTransferID 
	* @方法描述: 注册转账用 
	* @return     
	* @返回值 String    返回类型 
	* @作者：zdm mailto:zdmbill@163.com   
	* @创建时间 2011-5-26 下午02:51:44 
	* @修改时间 2011-5-26 下午02:51:44 
	* @版本 V1.0 
	* @异常 
	*/ 
	public static String CreateTransferID(){
		String FORMAT1 = "yyMMddHHmmss";
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT1);
		String tranDate = sdf.format(new Date());
		int current = 100000;
		synchronized (LOCK) {
			if (user_no > 999999) {
				user_no = 100000;
			}
			current += user_no++;
		}

		StringBuffer sb = new StringBuffer("TA");
		sb.append(tranDate).append(current);
		return sb.toString();
	}
}
